﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;
using NHibernate.Cfg;

namespace ExperimentUpon.Util
{
    public sealed class NHibernateUtils
    {
        private static ISessionFactory sessionFactory;

        static NHibernateUtils ()
        {
            Configuration config = new Configuration();
            config.Configure();
            sessionFactory = config.BuildSessionFactory();
        }

        public static ISession OpenSession() 
        {
            return sessionFactory.OpenSession();
        }

        public static ISession GetCurrentSession() 
        {
            return sessionFactory.GetCurrentSession();
        }

        public static void CloseSessionFactory() 
        {
            if (sessionFactory != null)
            {
                sessionFactory.Close();
            }
        }
    }
}
